﻿using HPIT.MemberPoint.Common;
using HPIT_LiuzuPoint.Entity.POCOModel;
using HPIT_LiuzuPoint.Entity.ViewModel;
using MPMS.DTOModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static MPMS.DTOModel.OperateResult;

namespace HPIT_LiuzuPoint.Business
{
   public class LogGiftLevelService:BaseService<ExchangLogs>
    {
        public OperateResult GetPagedGiftList(LogGiftSearchViewModel viewModel)
        {

            int rowCount = 0;
            //利用lambda表达式树返回一个IQueryable的接口

            var query = PredicateExtensions.True<ExchangLogs>();


            if (!string.IsNullOrWhiteSpace(viewModel.GiftCode))
                query = query.And(m => m.EL_GiftCode == viewModel.GiftCode);
            if (!string.IsNullOrWhiteSpace(viewModel.GiftName))
                query = query.And(m => m.EL_GiftName.Contains(viewModel.GiftName));
            if (viewModel.GiftLevel > 0)
                query = query.And(m => m.EL_ID == viewModel.GiftLevel);

            //调用BaseService封装好的分页方法
            var list = GetPageList(viewModel.Page, viewModel.Rows, ref rowCount, query, m => m.EL_ID, false);

            var data = new EasyUIDataGrid() { total = rowCount, rows = list };
            return new OperateResult(ResultStatus.Success, "", data);
        }
    }
}
